﻿ $(function($) {
      setDlgTitle(gPageParam.processPage.procDesc);

 	initPropertyEditor();
 	//alert($("#Ip").ipInput("val"));
	 
 	test();

 });

 function test() {
 	var ip = $("#ipinput").ipInput({
 		value: "127.0.0.1", //record.DefaultValue,
 		height: 22,
 		width: 300
 		//,disabled:record.Feild.indexOf("EqptName")<0?true:false
 	});

 	$("#tool_add").on("click", function() {
 		//alert($("#ipinput").ipInput("val"));
 		//alert($("#ipinput").val());
 		// alert(ip.val());
 		$("#ipinput").ipInput("enable");
 	});
 	$("#tool_delete").on("click", function() {
 		alert($("#ipinput").ipInput("val", "192.168.1.222"));
 		$("#ipinput").ipInput("disable");

 	});
 }

 function initPropertyEditor() {

 	var url = "table_xml/DriverMOPC.xml";
 	// prepare the data
 	//加载配置文件
 	var dataAdapter = new $.jqx.dataAdapter(tableSource(url), {
 		autoBind: true,
 		loadComplete: function() {
 			// get data records.
 			var records = dataAdapter.records;
			
 			var length = records.length;
 			var propertyEdit = $('<table></table').appendTo("#property_item_body");

 			for (var i = 0; i < length; i++) {
 				var record = records[i];
 				var propertyEditItem = $('<tr style="height:50px"></tr>').appendTo(propertyEdit);
 				var desc = $('<td style="width:150px"  class="property_desc"></td>').html(record.Desc).appendTo(propertyEditItem);
 				var valitem = $("<td></td>").appendTo(propertyEditItem);
 				//如果是枚举类型数据，获取枚举量，并形添加枚举值到droplist提供选择
 				if (record.DataType != "Enum") {

 					if (record.Field.indexOf("Ip") > -1) {
 						var value = $('<div   class="property_value" ><div>').attr("id", record.Field).appendTo(valitem); //.html(record.DefaultValue) 需要通过控件的设定值来设定初始值
 						value.ipInput({
 							value: "127.0.0.1", //record.DefaultValue,
 							height: 22,
 							width: 300
 							//,disabled:record.Feild.indexOf("EqptName")<0?true:false
 						});

 					} else {
 						var value = $('<input   class="property_value" />').attr("id", record.Field).val(record.DefaultValue).appendTo(valitem);

 						value.jqxInput({
 							placeHolder: "",
 							height: 22,
 							width: 300,
 							minLength: 1
 							//,disabled:record.Feild.indexOf("EqptName")<0?true:false
 						});
 					}

 				} else if (record.Enum) {



 				}
 			}	//设置默认值 
 			$("#ProcName").jqxInput({disabled:true});//.attr("disabled","true").attr("background","#131313");//实际只需要disabled有值就可以了
 			$("#ProcName").val(gPageParam.processPage.procName);
 		}
 		


 	});
 	// dataAdapter.dataBind();
 	// $(".dlg_btn").jqxButton({width:50,height:20,theme:theme});
 };